package com.cntcdt.api.db.dao;

import java.util.List;

import com.cntcdt.api.db.dao.base.UpdatePackageDaoBase;
import com.cntcdt.api.db.model.UpdatePackageModel;

/**
 * 这是cdt_update_package的Dao实现类
 */
public class UpdatePackageDao extends UpdatePackageDaoBase {
	/**
	 * UpdatePackageDao对象
	 */
	private static UpdatePackageDao instance = new UpdatePackageDao();

	/**
	 * 默认构造方法
	 */
	private UpdatePackageDao() {
	}

	/**
	 * 获得对象实例
	 */
	public static UpdatePackageDao getInstance() {
		return instance;
	}

	public List<UpdatePackageModel> findAfterVersionPackage(int version) {
		String sql = "SELECT * FROM " + TABLE + " WHERE opStatus = 0 and versionNum > ? order by versionNum";
		Object[] paramObjs = { version };
		List<UpdatePackageModel> modelList = this.queryModelList(sql, paramObjs);
		return modelList;
	}

	public List<UpdatePackageModel> findBySortTime(int sortTime) {
		sortTime = sortTime * 20;
		String sql = "SELECT * FROM " + TABLE + " WHERE opStatus = 0 order by versionNum desc limit ?,20";
		Object[] paramObjs = { sortTime };
		List<UpdatePackageModel> modelList = this.queryModelList(sql, paramObjs);
		return modelList;
	}

	public List<UpdatePackageModel> findByLast20Package() {
		String sql = "SELECT * FROM " + TABLE + " WHERE opStatus = 0 and version !='' order by addTime desc limit 20";
		List<UpdatePackageModel> modelList = this.queryModelList(sql, null);
		return modelList;
	}

	public List<UpdatePackageModel> findByLast20SoftPackage() {
		String sql = "SELECT * FROM " + TABLE
				+ " WHERE opStatus = 0 and softVersion !='' order by addTime desc limit 20";
		List<UpdatePackageModel> modelList = this.queryModelList(sql, null);
		return modelList;
	}

	public List<UpdatePackageModel> findByLast20PipePackage() {
		String sql = "select * from " + TABLE
				+ " where opStatus = 0 and pipeVersion !='' order by addTime desc limit 20";
		List<UpdatePackageModel> modelList = this.queryModelList(sql, null);
		return modelList;
	}
}
